<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"%>
<%@ page import="beans.User" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<title>用户</title>
<link type="text/css" rel=stylesheet href="${pageContext.request.contextPath}\css\userInfo.css">
</head>

<%
	User user=(User)session.getAttribute("user");				//获得从Login创建成功的用户对象
String path=request.getContextPath();
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";		//得到整个文件上下文的基本路径//防止用户因为路径问题照片显示不出来
//System.out.println(basePath);
%>
<body onload="showInfo('基本信息')">

<div id="main">
<div id="header">
<div id="wel">欢迎登录蚌埠学院图书馆</div>
<div id="type">借阅者界面</div>
<div id="username">你好:<%=user.getName() %></div>

<div id="img"><img src=<%=basePath+user.getPhoto()%>></div>

<div id="quit"><a href="javascript:close1()">退出登录</a></div>
</div>

<div id="select">
<br>
<div id="基本信息" onClick="showInfo(id)"><span>基本信息</span></div>
<br>
<div id="借阅记录" onClick="showInfo(id)"><span>借阅记录</span></div>
<br>
<div id="图书查询" onClick="query(id)"><span>图书查询</span></div>
<br>
</div>
<div id="content"></div>

</div>
</body>
<script>
function close1(){
	window.opener=null;
	window.location.href = 'about:blank';
	this.window.close();	
	window.open("../window.jsp");	
	
}
function showInfo(e){
	var url;
	var xmlHttp=new XMLHttpRequest();
	if(e=='基本信息'){
		url="../userBaseInfo.jsp";
	}else if(e=='借阅记录'){
		url="BorrowRecord?card_num="+<%=user.getCard_num() %>;
	}
		else if(e=='查看公告'){
		url="servlets/";
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			document.getElementById("content").innerHTML=xmlHttp.responseText;
		}
		
	}
	xmlHttp.send();
}
function query(){
	console.log("query");
	window.open("../bookInfo.jsp");
	
}

function changepwd(){
var oldpassword=prompt("原始密码:");
var newpassword;
		if(oldpassword==''){
			alert('密码不能为空!!!');
		}else{
			newpassword=prompt("新密码:");
		if(newpassword==''){
			alert('密码不能为空!!!');
		}else{
			var url="ChangePassword?oldpassword="+oldpassword+"&newpassword="+newpassword+"&id="+<%=user.getCard_num() %>;
			var xmlHttp=new XMLHttpRequest();
			xmlHttp.open("GET",url,true);
			xmlHttp.onreadystatechange=function(){
				if(xmlHttp.readyState==4){
					location.reload();
					alert(xmlHttp.responseText);
				}
			}
			xmlHttp.send();
		}
			
		}
		

}
</script>

</html>